package com.etao.tools.common.email;

import com.etao.tools.common.PropertyUtils;
import org.slf4j.LoggerFactory;

/**
 * Created by lyp on 2016/8/8.
 */
public final class EmailUtil {
   protected static final org.slf4j.Logger log = LoggerFactory.getLogger("com.etao.tools.common.email.EmailUtil");

    public static void sendEmail(String subject, String content,String[] to,String xlsName) {
        String path = Thread.currentThread().getContextClassLoader().getResource("").getPath()+ xlsName;
        log.info("发送全路径："+path);
        Email email = new Email();
        email.setMailHost(PropertyUtils.getProperty("ecb.mail.mailhost"));
        email.setMailTransportProtocol("smtp");
        email.setUserName(PropertyUtils.getProperty("ecb.mail.username"));
        email.setPassword(PropertyUtils.getProperty("ecb.mail.password"));
        email.setFrom(PropertyUtils.getProperty("ecb.mail.from"));
        email.setTo(to);
        email.setSubject(subject);
        email.setConent(content);
        email.setAttach(new String[] { path });
        try {
            email.send();
            log.info("发送《"+xlsName+"》成功！");
        } catch (Exception e) {
            e.printStackTrace();
            log.info("发送《"+xlsName+"》失败！原因：" + e.getMessage());
        }
    }

}
